package com.emqx;

import com.emqx.client.EmqClient;
import com.emqx.enums.QosEnum;
import com.emqx.properties.MqttProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;

/**
 * @author liguojun
 */
@SpringBootApplication
public class EmqxDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(EmqxDemoApplication.class, args);
    }

    @Autowired
    private EmqClient emqClient;

    @Autowired
    private MqttProperties properties;

    /**
     * 开启订阅指定主题消息
     */
    @PostConstruct
    public void init() {
        // 连接服务端
        emqClient.connect(properties.getUsername(), properties.getPassword());
        // 订阅一个主题
        emqClient.subscribe("HelloWorld/#", QosEnum.QoS2);
    }
}
